﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SmartSpace.UI.Silverlight;
using WorkSpace.UI.Windows;
using System.Json;
using WorkSpace.UI.Controls;
using WorkSpace.UI.WorkSpaceRef;

namespace WorkSpace.UI
{
    public partial class HomeView : AppView
    {
        private List<PersonalCategoryPart> _parts;
        private List<Button> _btns;

        public HomeView()
            : base(new Guid("{C4DDD80E-15B2-406B-8235-DF3D17FCDBE5}"), "Personal View")
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //CategoryListWindow window = new CategoryListWindow();
            //window.Show();
        }

        protected override void OnExtendShown()
        {
            if (IsFirstDisplay)
            {
                LoadDatas();
            }
        }

        private void LoadDatas()
        {
            WorkSpaceRef.WorkSpaceWebServiceSoapClient client = WorkSpaceModule.CreateWorkSpaceWebServiceProxy();
            client.GetPersonalCategoriesCompleted += new EventHandler<GetPersonalCategoriesCompletedEventArgs>(client_GetPersonalCategoriesCompleted);
            client.GetPersonalCategoriesAsync(this.Authentication.Account);
        }

        void client_GetPersonalCategoriesCompleted(object sender, GetPersonalCategoriesCompletedEventArgs e)
        {
            if (e.Error == null && e.Result.IsSuccess)
            {
                _parts = new List<PersonalCategoryPart>();
                for (int index = 0; index < e.Result.Data.Count; index++ )
                {
                    Category category = e.Result.Data[index];

                    TabItem item = new TabItem();
                    item.Header = category.Caption;

                    PersonalCategoryPart part = new PersonalCategoryPart(category, this.Authentication.Account);
                    item.Content = part;

                    _ctlTab.Items.Add(item);
                }
            }
        }
    }
}
